package activity.myrecyclerview;

import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.content_layout)
public class ContentActivity extends AppCompatActivity {


    @ViewById(R.id.webview)
    public WebView webview;
    @ViewById(R.id.app_bar_layout)
    public AppBarLayout mAppBarLayout;
    @ViewById(R.id.toolbar)
    public Toolbar toolbar;
    @ViewById(R.id.collapsing_toolbar_layout)
    public CollapsingToolbarLayout mCollapsingToolbarLayout;

    @AfterViews
    public void init() {
        mAppBarLayout.setVisibility(View.VISIBLE);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();

            }
        });
        mCollapsingToolbarLayout.setTitle("测试");
        mCollapsingToolbarLayout.setContentScrimColor(getResources().getColor(R.color.green_dark));
        mCollapsingToolbarLayout.setStatusBarScrimColor(getResources().getColor(R.color.green_dark));
        webview.loadUrl("http://www.baidu.com");
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        // 开启DOM storage API 功能
        webview.getSettings().setDomStorageEnabled(true);
        // 开启database storage API功能
        webview.getSettings().setDatabaseEnabled(true);
        // 开启Application Cache功能
        webview.getSettings().setAppCacheEnabled(true);
        webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }
}
